package net.jblog.business.facade.impl;

import java.util.List;

import net.jblog.business.IConstantes;
import net.jblog.business.dao.CategoryDao;
import net.jblog.business.dao.CounterDao;
import net.jblog.business.facade.CategoryFacade;
import net.jblog.data.model.Category;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class CategoryFacadeImpl implements CategoryFacade, IConstantes {
	private CategoryDao categoryDao;
	private CounterDao counterDao;
	
	public void save(Category entity) {
		Long id = getCounterDao().nextValCategory();
		Key key = KeyFactory.createKey(Category.class.getSimpleName(), id);
		entity.setId(id);
		entity.setKey(key);
		getCategoryDao().persist(entity);
	}

	public void update(Category entity) {
		getCategoryDao().merge(entity);
	}

	public Category findById(Long id) {
		return getCategoryDao().findById(id);
	}
	
	public Category findDefaultCategory() {
		return getCategoryDao().findById(COUNTER_INITIALIZE);
	}
	
	public List<Category> findAllCategories() {
		return getCategoryDao().findAllCategories();
	}
	
	public List<Category> findCategoriesParent() {
		return getCategoryDao().findCategoriesParent();
	}

	public List<Category> findByCriteria(int index, int number, String order,
			boolean ascending) {
		return getCategoryDao().findByCriteria(index, number, order, ascending);
	}

	public CategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public CounterDao getCounterDao() {
		return counterDao;
	}

	public void setCounterDao(CounterDao counterDao) {
		this.counterDao = counterDao;
	}

	

}
